<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="98px">
      <el-form-item label="企业" prop="enterpriseId">
        <el-select
          size="small"
          v-model="queryParams.enterpriseId"
          filterable
          placeholder="请选择企业"
          clearable>
          <el-option
            v-for="item in zsCustomerList"
            :key="item.id"
            :label="item.enterpriseName"
            :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['life:feLeaseRecord:export']"
        >导出
        </el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="feLeaseRecordList"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="企业" align="center" prop="enterpriseName"/>
      <el-table-column
        label="租赁开始时间"
        align="center"
        prop="beginTime"
        width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.begin, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="租赁结束时间"
        align="center"
        prop="endTime"
        width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.end, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="行业分类" align="center" prop="enterpriseType"/>
      <el-table-column label="生产分类" align="center" prop="productionType"/>
      <el-table-column label="垃圾费(元)" align="center" prop="solid"/>
      <el-table-column label="污水处理费(元)" align="center" prop="sewage"/>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.row)"
            v-hasPermi="['life:feLeaseRecord:edit']">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <!-- 添加或修改企业以及对应的一些费用对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="企业" prop="qyEnterpriseName" >
          <el-input disabled v-model="form.qyEnterpriseName"/>
        </el-form-item>
        <el-form-item label="垃圾费(元)" prop="solid">
          <el-input v-model="form.solid" placeholder="请输入垃圾费(元)"/>
        </el-form-item>
        <el-form-item label="污水处理费(元/月/吨)" prop="sewage">
          <el-input v-model="form.sewage" placeholder="请输入污水处理费(元)"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listQyEnterpriseFee,
  updateQyEnterpriseFee,
  getOtherFee
} from '@/api/smartParks/operatingFee/leasing'
import {
  addQyEnterprise,
  listQyEnterprise,
  updateQyEnterprise
} from '@/api/smartParks/merchants/merchantsCompanySettlein'


export default {
  name: 'Leasing',
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 租赁记录表格数据
      feLeaseRecordList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      effectOpen: false,
      billOpen: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseId: null,
      },
      // 表单参数
      form: {
        id: null,
        solid: null,
        sewage: null,
        qyEnterpriseName: null
      },
      // 表单校验
      rules: {
      },
      flag: true,

    }
  },

  created() {
    this.getList()
  },
  methods: {
    /** 查询租赁记录列表 */
    getList() {
      this.loading = true
      listQyEnterpriseFee(this.queryParams).then((response) => {
        this.feLeaseRecordList = response.rows
        this.total = response.total
        this.loading = false
      })
    },

    handleEdit(row){
      this.reset()
      const id = row.id || this.ids
      getOtherFee(id).then((response) =>{
        this.form = response.data
        this.open = true
        this.title = '修改企业以及对应的一些费用'
      })
    },


    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        solid: null,
        sewage: null,
        id: null,
        enterpriseId: null,
        enterpriseName: null,
        beginTime: null,
        endTime: null,

      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.enterpriseId = null
      this.resetForm('queryForm')
      this.handleQuery()
    },

    submitForm(){
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateQyEnterpriseFee(this.form).then(response => {
              this.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    }






  }
}
</script>
